package DAO;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.classic.Session;
import org.hibernate.criterion.Restrictions;

import to.Email;
import util.HibernateUtil;

public class EmailDAO {

	public List<Email> buscaEmailPorPessoa(Integer id) {

		List<Email> listaRetorno = new ArrayList<>();
		Session session = null;

		try {
			
			session = HibernateUtil.getSessionFactory().openSession();
			Criteria criteria = session.createCriteria(Email.class, "e")
					.createAlias("e.pessoa", "p");
			criteria.add(Restrictions.eq("p.id", id));
			listaRetorno = (List<Email>) criteria.list();

		} catch (Exception e) {
			e.printStackTrace();
		}
		return listaRetorno;
	}

}
